#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
详细调试脚本：专门查看联运方案构建的详细过程
"""

import sys
import os
sys.path.append(os.path.dirname(__file__))

from liudang_realtime import (
    get_flight_data_hub_first, 
    build_flight_rail_combos,
    _norm_city
)

def test_detailed_multimodal():
    """详细测试联运方案构建"""
    print("=" * 60)
    print("详细测试联运方案构建")
    print("=" * 60)
    
    origin = "大连"
    destination = "合肥"
    origin_address = "大连交通大学"
    destination_address = "合肥南站"
    date = "2025-09-29"
    
    # 获取航班数据
    flights = get_flight_data_hub_first(origin, destination, date)
    print(f"输入航班数量: {len(flights)}")
    
    # 只测试南京的航班
    nanjing_flights = [f for f in flights if f.get('nearby_city') == '南京']
    print(f"南京航班数量: {len(nanjing_flights)}")
    
    if nanjing_flights:
        print(f"\n测试第一个南京航班:")
        test_flight = nanjing_flights[0]
        print(f"  航班信息: {test_flight.get('origin')} -> {test_flight.get('destination')}")
        print(f"  is_nearby: {test_flight.get('is_nearby')}")
        print(f"  nearby_type: {test_flight.get('nearby_type')}")
        print(f"  nearby_city: {test_flight.get('nearby_city')}")
        
        # 构建联运方案
        combos = build_flight_rail_combos(
            destination, date, [test_flight], 
            origin_address, origin, destination_address, 
            "price", "auto"
        )
        
        print(f"\n输出联运方案数量: {len(combos)}")
        
        for i, combo in enumerate(combos):
            print(f"\n方案 {i+1}:")
            print(f"  类型: {combo.get('type', '')}")
            print(f"  总时间: {combo.get('total_time', '')} 小时")
            print(f"  总价格: ¥{combo.get('total_price', 'N/A')}")
            print(f"  换乘次数: {combo.get('transfers', 0)}")
            print(f"  换乘城市: {combo.get('transfer_city', '')}")
            
            details = combo.get('details', [])
            print(f"  详情段数: {len(details)}")
            for j, detail in enumerate(details):
                print(f"    {j+1}. {detail.get('type', '')} | {detail.get('origin', '')} -> {detail.get('destination', '')} | {detail.get('departure_time', '')} - {detail.get('arrival_time', '')}")

if __name__ == "__main__":
    test_detailed_multimodal()